import $ from 'jQuery';
(function () {
    let $accountBox = null;
    let $vue = new Vue({
        el: '.main-hook',
        data: {
            leaseType: [{id: 1, name: '项目A'}, {id: 2, name: '项目B'},{id: 3, name: '项目C'}, {id: 4, name: '项目D'}],
            receiveStatus:[{id: 1, name: '分组a'}, {id: 2, name: '分组b'},{id: 3, name: '分组c'},{id: 4, name: '分组d'}],
            key  : [{id: 0, name: '分组编号'}],
            boxs: {
                box1: {show: true, hook: '.box1-hook', lock: true, url: '', params: {}},
                box2: {show: false, hook: '.box2-hook', url: '', params: {}},
                box3: {show: false, hook: '.box3-hook', url: '', params: {}},
                box4: {show: false, hook: '.box4-hook', url: '', params: {}}
            },
            roleList: []
        },
        created: function () {
            M.Request.getRoleList(true, (roleList, ret) => {
                this.roleList = roleList;
            });
        },
        methods: {
            emitPage: function () {
                M.Page.load(this.boxs);
            },
            // 上一页
            prePage: function () {
                M.Page.prePage(this.boxs);
            },
            searchKey:function(){
                $('.search-hook').trigger('click');
            },
            // 触发刷新页(当前显示的页面)
            refreshPage: function () {
                M.Page.refreshPage(this.boxs);
            },
            // 切换图表
            changeChart: function () {
                M.Page.emit(URI.REPORT.HISTORY_TIME.INFO_CHAR.PAGE);
                var $form = $('.form-hook');
                var formParams = $form.serializeJson();
                IOT.setSessionStore(URI.REPORT.HISTORY_TIME.INFO_CHAR.PAGE, JSON.stringify(formParams));
            },
            exportOrder:function(){//下载
                // var staticServer = $('#staticServer').val();
                IOT.showOverlay('正在导出，请稍等...');
                IOT.getServerData(URI.REPORT.HISTORY_TIME.EXPORT,{}, (ret) => {
                    IOT.tips(ret.msg || '操作失败，请重试！', 'error', 1000, null);
                    IOT.hideOverlay();
                    if (ret && ret.code === 200) {
                        window.location.href = ret.data.substr(1);
                        // console.log(window.location.href);
                        IOT.tips('导出完成！', 'success');
                    } else {
                        IOT.tips(ret.message || '服务器请求失败，稍后再试！', 'error');
                    }
                });
                return false;
            }
        },
        mounted: function () {
            let thiz = this;
            this.$nextTick(() => {
                let tableHookName = '.history-time-table-hook';
                $accountBox = $('.history-time-hook');
                var $form = $accountBox.find('.form-hook');
                modal.initDate("startdate","enddate");
                // 查询
                $form.off('submit').on('submit', function () {
                    $(tableHookName).bootstrapTable('onCustomSearch');
                    return false;
                });
                var $tableHook = $accountBox.find(tableHookName).bootstrapTable({
                    scrollbar: 'history-time-table-body',
                    striped: true, // 设置为 true 会有隔行变色效果
                    pagination: true, // true 显示分页
                    paginationDetail: true, // 分页详情
                    sidePagination: 'server', // 服务器端
                    method: 'post',
                    url: URI.REPORT.HISTORY_TIME.LIST,
                    debug: false,
                    cache: false,
                    pageNumber: 1,
                    pageSize: 20,
                    smartDisplay:false,
                    // fixedColumns: true,
                    customButton: '',
                    customQueryParams: function (params) {
                        var formParams = $form.serializeJson();
                        var queryParams = $.extend({}, params, formParams);
                        //console.log(queryParams);
                        return queryParams;
                    },
                    onLoadSuccess: function (data) {
                        //console.log(JSON.stringify(data));
                    },
                    onLoadError: function (status, xhr) {
                    },
                    onCheckAll: function (rows) {

                    },
                    columns: [
                        /*{
                            field: '', checkbox: true, align: 'center', fixedLeft: true, width: 60,
                            events: {
                                'change .checkbox-hook': function (e, value, row, index) {
                                    console.log('复选框: ' + value);
                                }
                            }
                        },*/
                        // {
                        //     field: 'no', title: '序号', align: 'center', width: 50,tips:true,
                        //     formatter: function (value, row, index) {
                        //         var pageSize =  $accountBox.find(tableHookName).bootstrapTable('getOptions').pageSize;     //通过table的#id 得到每页多少条
                        //         var pageNumber = $accountBox.find(tableHookName).bootstrapTable('getOptions').pageNumber; //通过table的#id 得到当前第几页
                        //         return pageSize * (pageNumber - 1) + index + 1;    // 返回每条的序号： 每页条数 *（当前页 - 1 ）+ 序号
                        //     }
                        // },
                        {
                            field: 'mobile', title: '项目名称', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'mobile', title: '分组名称', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'userName', title: '单灯ID', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'gender', title: '单灯名称', align: 'center', fixedLeft: true,width:80,
                        },
                        {
                            field: '', title: '标准开灯时间', align: 'center', fixedLeft: true,width: 140,tips: true,
                            formatter: function (value, row, index) {
                                /* 0未确认；1已确认； */
                                return value != null ?  new Date(value).Format('yyyy-MM-dd hh:mm:ss') : "-";
                            }
                        },
                        {
                            field: '', title: '标准关灯时间', align: 'center', fixedLeft: true,width: 140,tips: true,
                            formatter: function (value, row, index) {
                                /* 0未确认；1已确认； */
                                return value != null ?  new Date(value).Format('yyyy-MM-dd hh:mm:ss') : "-";
                            }
                        },
                        {
                            field: '', title: '实际开灯时间', align: 'center', fixedLeft: true,width: 140,tips: true,
                            formatter: function (value, row, index) {
                                /* 0未确认；1已确认； */
                                return value != null ?  new Date(value).Format('yyyy-MM-dd hh:mm:ss') : "-";
                            }
                        },
                        {
                            field: '', title: '实际关灯时间', align: 'center', fixedLeft: true,width: 140,tips: true,
                            formatter: function (value, row, index) {
                                /* 0未确认；1已确认； */
                                return value != null ?  new Date(value).Format('yyyy-MM-dd hh:mm:ss') : "-";
                            }
                        }
                    ]
                });
            });
        }
    });
})();